package util;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import baseDao.TaskListDao;
import entity.TaskList;

public class GetSqlSession {
	
		//李佳晓 11.30  2:17
		//修改执行状态
			public static Integer updateStatus(Integer id,String msg){
				TaskList tk=new TaskList();
				tk.setTaskId(id);
				//传入执行状态
				tk.setExecutingState(msg);
				TaskListDao dao = getSession().getMapper(TaskListDao.class);
				return dao.update(tk);
			}

	public static SqlSession getSession() {

		Reader reader = null;
		SqlSession session = null;
		try {
			reader = Resources.getResourceAsReader("mybatis.xml");
			SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);
			session = sessionFactory.openSession(true);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return session;
	}
	
	public static void closeSession(SqlSession session) {
		if(session!=null){
			session.close();
		}
	}
	
	

}
